﻿-- =============================================
-- Author:		zengfei	
-- Create date: 03m/16/2012
-- Description:	更新商品库存
-- =============================================
CREATE PROCEDURE [dbo].[Usp_UpdateBalance]
	@p_ProductNo	varchar(10),
	@p_Warehouse	int,
	@p_Qty	numeric(15, 2),			-- @p_Qty提供的值为NewQty - OldQty的差
	@p_AidQty	numeric(15, 2)		-- @p_AidQty同@p_Qty
AS
if exists(select ProductNo from Balance where ProductNo = @p_ProductNo and Warehouse = @p_Warehouse)
begin
	update Balance 
		set Qty = Qty + @p_Qty, 
			AidQty = AidQty + @p_AidQty 
		where ProductNo = @p_ProductNo and Warehouse = @p_Warehouse
end
else
begin
	insert into Balance (ProductNo, Warehouse, Qty, AidQty)
		values (@p_ProductNo, @p_Warehouse, @p_Qty, @p_AidQty)
end